Skip to content

refactor: Build RBAC with recommended labels#821

Open
adwk67 wants to merge 7 commits into
mainfrom
feat/smooth-operator/rbac-consolidate-labels
Open

refactor: Build RBAC with recommended labels#821
adwk67 wants to merge 7 commits into
mainfrom
feat/smooth-operator/rbac-consolidate-labels

Conversation

@adwk67

@adwk67 adwk67 commented Jul 20, 2026

Copy link
Copy Markdown
Member

Description

Part of: stackabletech/issues#869

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Helm chart can be installed and deployed operator works
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible
  • Links to generated (nightly) docs added
  • Release note snippet added

Reviewer

  • Code contains useful comments
  • (Integration-)Test cases added
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added
  • Links to generated (nightly) docs added
  • Release note snippet added
  • Add type/deprecation label & add to the deprecation schedule
  • Add type/experimental label & add to the experimental features tracker

@adwk67
adwk67 changed the base branch from main to feat/smooth-operator/introduce-builder July 20, 2026 10:44
Base automatically changed from feat/smooth-operator/introduce-builder to main July 21, 2026 15:09
@adwk67 adwk67 self-assigned this Jul 21, 2026
@adwk67
adwk67 force-pushed the feat/smooth-operator/rbac-consolidate-labels branch from 0fbde39 to 6866383 Compare July 21, 2026 15:48
@siegfriedweber
siegfriedweber self-requested a review July 22, 2026 06:53

/// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
/// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
pub fn rbac_resource_names(&self) -> role_utils::ResourceNames {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I read this, the following questions came to my mind: Why are there two resource-name functions? Why can't a single function provide the resource names for all resources? What makes the RBAC resources so special? In reality, though, the situation is that rbac_resource_names provides the names for the resources at the cluster level, whereas resource_names provides the names for the role-group resources. The fact that rbac_resource_names (currently) only provides the names for RBAC resources is more of a coincidence. In the future it could, for example, also provide the name for the discovery ConfigMap. I would either name the two functions cluster_resource_names and role_group_resource_names (or something along those lines), or somehow combine them both.

The OpenSearch operator does not have this problem because it has a separate context for the role resources (https://github.com/stackabletech/opensearch-operator/blob/26.7.0/rust/operator-binary/src/controller/build/role_builder.rs#L48) and the role-group resources (https://github.com/stackabletech/opensearch-operator/blob/26.7.0/rust/operator-binary/src/controller/build/role_group_builder.rs#L210) respectively. That could be another way to solve it.
(The OpenSearch CRD has only one role, so the cluster-level resources were accidentally moved into the RoleBuilder which is wrong and should be changed.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to cluster_resource_names and role_group_resource_names: 9ef8a4b

Comment on lines +16 to +18
// The group listener is a role-level object, so a constant `none` role-group is used as the
// role-group label value.
stackable_operator::constant!(PLACEHOLDER_LISTENER_ROLE_GROUP: RoleGroupName = "none");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this placeholder there only for backwards-compatibility or is this the desired solution?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was inconsistent naming. Renamed here to what we have elsewhere: 856af92 (the constant value itself was already used as such in the pre-PR code)

/// Both resources are shared by the whole cluster rather than tied to a role or role group, so
/// the recommended labels carry `none` for both values.
fn rbac_labels(cluster: &ValidatedCluster) -> Labels {
cluster.recommended_labels_for(&NONE_ROLE_NAME, &NONE_ROLE_GROUP_NAME)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be variants for recommended_labels_for specific to role and cluster resources.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we can keep it as it is for now, as all 12 operators should be consistent and the PRs a little easier to review. We can make this change (plus the one in your comment below) when we move the labels stuff into op-rs in a subsequent iteration. I've added it to the TODOs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the labels are always the recommended ones, then we could just create the labels in rbac::build_service_account and rbac::build_role_binding. Once rbac_labels() is gone, there is no longer any reason for this file to exist, because it merely forwards function calls without making any noteworthy contribution.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see above)

Comment on lines +356 to +358
role.to_string()
.parse()
.expect("an AirflowRole serialises to a valid RoleName")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumption can easily be checked in a unit test by iterating over the variants of AirflowRole.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ce02972

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants